var Client = require('ftp');
var fs = require('fs');
var c = new Client();
// 本地目录
var uploadPath = 'dist'

c.on('ready', function() {
    uploadFtp(uploadPath);
});

function uploadFtp(path) {  
    fs.readdir(path, function(err, files) {  
        if (err) throw err;
        files.forEach(function(item) {  
            var tmpPath = path + '/' + item;
            var prePath = tmpPath.replace(uploadPath+'/', '');
            fs.stat(tmpPath, function(err1, stats) {  
                if (err1) throw err1;
                if (stats.isDirectory()) {
                    uploadFtp(tmpPath);
                    console.log('path:"' + prePath+'"');
                    c.mkdir(prePath, true, function(err, parameter){
                        if (err) throw err;
                        c.end();
                    })
                } else {
                    console.log('file:"' + prePath+'"');
                    c.put(tmpPath, prePath, function(err) {
                        if (err) throw err;
                        c.end();
                    });
                }  
            })
        }); 
    });  
} 

var option={host:"10.27.219.12","port":21,"user":"suning","password":"admin12"}
//ftp: 10.27.219.12  suning   admin12
c.connect(option);  

